package com.bubblegumproject.ogo.action;

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.UUID;

/**
 * Simple implementation of the {@link Conversation} interface.
 *
 * @author Azubuko Obele (buko.obele@gmail.com)
 */
public class SimpleConversation implements Conversation {

    private String id = UUID.randomUUID().toString();

    private Flow flow;

    private Source source;

    private SimpleAgent agent;

    private Deque<Action> history = new ArrayDeque<Action>();

    public SimpleConversation(Action initialAction, SimpleAgent agent) {
        assert(initialAction != null);
        this.flow = initialAction.getFlow();
        this.source = initialAction.getSource();
        this.agent = agent;
        record(initialAction);
    }

    public String getId() {
        return id;
    }

    public void execute(Action action) {
        agent.execute(flow, action);           
    }

    public Flow getFlow() {
        return flow;
    }

    public Source getSource() {
        return source;
    }

    private void record(Action action) {
        assert(action != null);
        history.push(action);
    }

    public void destroy() {
        ; // do nothing
    }
}
